const express = require('express')
const router = express.Router()

const db = require('../../db/conn_blog')
const responsed = require('../../utils/response')

router.get('/', async (req, res, next) => {
  const result = await db.getArticleById(req.query.id).catch(err => err)
  
  if (result === 'DATABASE ERROR, connection failed!')
    res.json(responsed(0, '获取文章信息失败, DATABASE ERROR , connection failed!', false))

  if (result.length > 0) {
    res.json(responsed(1, '获取目录信息成功', { strMd: result[0].blog_article_content, blog_submenu_name: result[0].blog_submenu_name }))
  }
  else res.json(responsed(0, '获取文章信息失败', false))
})

module.exports = router